module queueForCrossBar (
    input wire clk,
    input wire rst,
    input wire enqueue_en,
    input wire [5:0] enqueue_priority,
    input wire [15:0] enqueue_value,
    input wire dequeue_en,
    output reg [5:0] dequeue_priority,
    output reg [15:0] dequeue_value,
    output reg queue_empty,
    output reg [5:0] queue_head_priority
);
    //队列存储
    reg [5:0] queue_priority [0:7];
    reg [15:0] queue_value [0:7];
    //队列指针
    reg [3:0] head, tail;
    //队头元素优先级
    reg [5:0] head_priority;
    
    always @(posedge clk) begin
        if (rst) begin
            //初始化队列指针
            head <= 0;
            tail <= 0;
            //向外释放队列为空的信号
            queue_empty <= 1;
        end
        else begin
            if (enqueue_en) begin
                //元素入队
                queue_priority[tail] <= enqueue_priority;
                queue_value[tail] <= enqueue_value;
                tail = (tail + 1) % 8;
            end

            if (dequeue_en) begin
                //数据出队
                dequeue_priority <= queue_priority[head];
                dequeue_value <= queue_value[head];
                head = (head + 1) % 8;
            end

            if (head == tail) begin
                //队列为空
                queue_empty <= 1'b1;
            end
            else begin
                //队列非空，向外展示队头元素
                queue_empty <= 1'b0;
                queue_head_priority <= queue_priority[head];
            end
        end
    end
endmodule